import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import weixinShare from '../../lib/weixinShare';
import { addErrorListener } from '../../lib/handleError';

import AJAX from '../../lib/ajax';

const Dialog = require('../MyPackage/components/Dialog')

require('../../lib/rem');
require('../../styles/common.less');
require('./CouponsUnAuth.less');
require('../../styles/iconfont/iconfont.css');

class CouponsUnAuthElem extends Component {
  constructor(props) {
    super(props)

    this.state = {
      isReady: false,     //是否可以加载页面
      userInfo: {},
      type: 1,
    };
  }

  componentWillMount() {
    addErrorListener()()
    weixinShare.hideAll()
  }

  componentDidMount() {
    const { href } = window.location;
    const type = href.split('?type=')[1];
    if (type) this.setState({ type });
    AJAX.request("user_home", {}, (data) => {
      if (data.code === 0) {
        this.setState({
          userInfo: data.body
        });
      }
    }, './Coupons')

    setTimeout(() => {
      this.setState({
        isReady: true, //是否可以加载页面
      })
    }, 200)
  }

  render () {
    const { type } = this.state;
    return (
      this.state.isReady &&
      <div className="coupons">
        <div className="coupons_header">
          {/* <span
            className="icon iconfont iconIcon_left"
            onClick={() => history.back(-1)}
          >
            返回
          </span> */}
          <label className="header_title">券任务</label>
        </div>
        {type === '1' ? (
          <div className="unAuth">
            <p>未能获取到手机号与地址信息</p>
            <img src="https://cdn2.jinlb.cn/pic/8c/8c/8c8cee41c2ad36e87bd74033529b8448.png" alt="取件小程序" />
          </div>
        ) : (
          <div className="unAuth">
            <p>未能获取到地址信息</p>
            <img src="https://cdn2.jinlb.cn/pic/2e/bb/2ebbc39535c593575ca23480fcc347d5.png" alt="取件小程序" />
          </div>
        )}
      </div>
    );
  }
}
ReactDOM.render(<CouponsUnAuthElem />, document.getElementById('app'));
if (module.hot) {
  module.hot.accept();
}

